package com.zxh.okretrofit.view;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.zxh.okretrofit.R;
import com.zxh.okretrofit.listener.HttpOnPressListener;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * to handle interaction events.
 */
public class LoadingFragment extends DialogFragment implements HttpOnPressListener{

    private ProgressBar mPdLoad;
    private TextView mTvLoad;
    private View view;

    public LoadingFragment() {
        // Required empty public constructor
    }

    public static LoadingFragment newInstance() {
        LoadingFragment fragment = new LoadingFragment();
        return fragment;
    }

    public void onShow(){
        show(getFragmentManager(),this.getClass().getSimpleName());
    }

    @Override
    public void onDismiss() {
        dismiss();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_loading, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mPdLoad = (ProgressBar) view.findViewById(R.id.pd_load);
        mTvLoad = (TextView) view.findViewById(R.id.tv_load);
    }

    /**
     * 设置进度条上的文字
     *
     * @param str
     */
    protected void setText(String str) {
        mTvLoad.setText(str);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }


}
